package master.ghrm.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;

@Entity
public class ChoiceQuestion extends Question {

	private static final long serialVersionUID = 1L;

	private static final String[] EXCL_ADDITIONAL = {};

	@Column(name = "single_choice")
	private Boolean singleChoice;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "question")
	private List<QuestionOption> questionOptions;

	/**
	 * Default constructor, persistence use.
	 */
	public ChoiceQuestion() {
		super();
		this.singleChoice = Boolean.TRUE;
		this.questionOptions = new ArrayList<QuestionOption>();
	}

	/**
	 * @param name name of the question
	 * @param text text of the question
	 * @param isSingleChoice if the question is single choice question
	 */
	public ChoiceQuestion(String name, String text, Boolean isSingleChoice) {
		super(name, text);
		this.singleChoice = isSingleChoice;
		this.questionOptions = new ArrayList<QuestionOption>();
	}

	/**
	 * Copy constructor.
	 * 
	 * @param question question to copy
	 * @param isSingleChoice is single choice.
	 */
	public ChoiceQuestion(Question question, Boolean isSingleChoice) {
		this.setQuestionId(question.getQuestionId());
		this.setName(question.getName());
		this.setText(question.getText());
		this.setQuestionType(question.getQuestionType());
		this.setMustBeAnswered(question.getMustBeAnswered());
		this.setEvalCategory(question.getEvalCategory());
		this.singleChoice = isSingleChoice;
		this.questionOptions = new ArrayList<QuestionOption>();
	}

	/**
	 * @return is the question single choice question
	 */
	public Boolean getSingleChoice() {
		return this.singleChoice;
	}

	/**
	 * @param isSingleChoice if the question is single choice question
	 */
	public void setSingleChoice(Boolean isSingleChoice) {
		this.singleChoice = isSingleChoice;
	}

	/**
	 * @return list of options
	 */
	public List<QuestionOption> getQuestionOptions() {
		return this.questionOptions;
	}

	/**
	 * @param questionOptionList list of options
	 */
	public void setQuestionOptions(List<QuestionOption> questionOptionList) {
		this.questionOptions = questionOptionList;
	}

	@Override
	protected String[] getAdditionalExclAttr() {
		return EXCL_ADDITIONAL;
	}
}
